const fs = require('fs')

function updateVersion() {
    const filePath = './src/index.js'
    const con = fs.readFileSync(filePath, { encoding: 'utf8' })
    const lines = con.split('\n')
    const versionLineIdx = lines.findIndex(line => line.startsWith('// @version'))
    const versionLine = lines[versionLineIdx]
    console.log("🚀 ~ updateVersion ~ versionLine:", versionLine)
    const newVersionLine = versionLine.replace(/(\d+\.\d+.)(\d+)/, (m, startPart, lastPart) => {
        return startPart + (lastPart * 1 + 1)
    })
    console.log("🚀 ~ newVersionLine ~ newVersionLine:", newVersionLine)
    lines[versionLineIdx] = newVersionLine

    const newCon = lines.join('\n')


    fs.writeFileSync(filePath, newCon)
}

updateVersion()